jQuery(document).ready(function() {
	// if (typeof RegExLearning == "undefined")
		jQuery.getScript("/RegExLearning.js");
		regExLearningTest.testThatTheAppropriateDOMElementsArePresent();
		regExLearningTest
				.testThatAttachingSearchEventToAnElementItIsActuallyAttached();
	});

var regExLearningTest = {
	testThatTheAppropriateDOMElementsArePresent : function() {

		page = {
			evaluateString : jQuery.extend( {},
					jQuery("input[name='evaluateString']"))
		};
		test(
				"testThatTheAppropriateDOMElementsArePresent",
				function() {
					expect(6);
					ok(page.evaluateString.length > 0,
							"Input evaluateString exists");
					ok(jQuery("input[name='regularExpression']").length > 0,
							"Input regularExpression exists");
					ok(jQuery("input[name='replacementText']").length > 0,
							"Input replacementText exists");
					ok(
							jQuery("[name='evaluateRegExForFindClickable']").length > 0,
							"Element evaluateRegExForFindClickable exists");
					ok(
							jQuery("[name='evaluateRegExForFindAndReplaceClickable']").length > 0,
							"Element evaluateRegExForFindAndReplaceClickable exists");
					ok(jQuery("[name='showResultsValue']").length > 0,
							"Element showResultsValue exists");

				});
	},

	testThatAttachingSearchEventToAnElementItIsActuallyAttached : function() {
		test("testThatAttachingSearchEventToAnElementItIsActuallyAttached",
				function() {

					expect(1);

					RegExLearning.attachFindMethodToFindClickableElement();
					var events = jQuery(
							"[name='evaluateRegExForFindClickable']").data(
							"events");
					var foundHandler = false;

					jQuery(events.click).each(function(index, element) {
						if (element.handler == RegExLearning.find)
							foundHandler = true;

					});

					ok(foundHandler, "The Click Handler was attached");
				});

	}
};
